package net.pec.geotools_svg.svg_conversion;

import java.net.MalformedURLException;
import java.net.URL;


import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class svgWebMapServiceImage {
	
	public static Element getMapImage(Document doc, Double Yaxismidpoint, Double MinX, 
			Double MinY, Double viewboxWidth, Double viewboxHeight,
			int Rotation, String lyrname, int imageResolution,
			String opacity, String espgStringCode) throws MalformedURLException{
		
		Double MaxX = MinX+viewboxWidth;
		Double MaxY = MinY+viewboxHeight;
		
		double coorddiff = MaxY - Yaxismidpoint;
		Double newcoord = Yaxismidpoint-coorddiff;
		
		String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
		Element imageElement = doc.createElementNS(svgNS, "image");
		imageElement.setAttributeNS(null,"x",Double.toString(MinX));
		imageElement.setAttributeNS(null,"y",Double.toString(newcoord));
		imageElement.setAttributeNS(null,"width","100%");
		imageElement.setAttributeNS(null,"height","100%");
		imageElement.setAttributeNS(null,"id","Basemap");
		imageElement.setAttributeNS(null, "opacity", opacity);
		//imageElement.setAttributeNS(null, "preserveAspectRatio", "xMidYMid slice");
		
				
		String strURL = "http://schroeder.geo.uzh.ch:8080/geoserver/wms?service=WMS&version=1.1.0&angle="+Rotation+"&transparent=true&request=GetMap&layers="+lyrname+
		   "&styles=&bbox="+MinX+","+MinY+","+MaxX+","+MaxY+"&width="+imageResolution+"&height="+imageResolution+"&srs="+espgStringCode+"&format=image/png";
		System.out.println(strURL);
		imageElement.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",strURL);
		return imageElement;
		
	}
	
	
			
}
